﻿unit uCadCliente;

interface

uses
  Windows,
  Messages,
  SysUtils,
  Variants,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  DBCtrls,
  ComCtrls,
  DB,
  ADODB,
  Menus,
  uPadrao,
  FocusDBGrid, Grids, DBGrids;
type
  Tfm_Cad_Cliente = class(Tfm_Padrao)
    pc_Principal: TPageControl;
    ts_Cad_Interno: TTabSheet;
    ts_Cons_Externa: TTabSheet;
    dbGrid_Consulta_Externa: TFocusDbGrid;
    dbGrid_Cadastro_Interno: TFocusDbGrid;
    pm_Principal: TPopupMenu;
    mi_Importar: TMenuItem;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure pm_PrincipalPopup(Sender: TObject);
    procedure mi_ImportarClick(Sender: TObject);
  private
  public
  end;

var
  fm_Cad_Cliente: Tfm_Cad_Cliente;

implementation

uses

  uErro;

{$R *.dfm}

procedure Tfm_Cad_Cliente.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  //dbGrid_Consulta_Externa.SaveColumnState(UnitName);
  //dbGrid_Cadastro_Interno.SaveColumnState(UnitName);
  Liberar(fm_Cad_Cliente);
  inherited;
end;

procedure Tfm_Cad_Cliente.FormShow(Sender: TObject);
begin
  try
    dbGrid_Consulta_Externa.Iniciar;
    dbGrid_Cadastro_Interno.Iniciar;
    //dbGrid_Consulta_Externa.LoadColumnState(UnitName+'_'+dbGrid_Consulta_Externa.Name);
    //dbGrid_Cadastro_Interno.LoadColumnState(UnitName+'_'+dbGrid_Cadastro_Interno.Name);
  except
    on E:Exception do
    begin
      TErro.GravarErro(Self.ClassName,'FormShow',E,True);
    end;
  end;
end;

procedure Tfm_Cad_Cliente.pm_PrincipalPopup(Sender: TObject);
begin
  mi_Importar.Enabled := (pc_Principal.ActivePage = ts_Cons_Externa) and
                         (not dbGrid_Consulta_Externa.IsNull);
  mi_Importar.Visible := mi_Importar.Enabled;
end;

procedure Tfm_Cad_Cliente.mi_ImportarClick(Sender: TObject);
begin
  dbGrid_Consulta_Externa.Exportar('códigocliente');
  dbGrid_Cadastro_Interno.AtualizarConsulta; {Consulta novamente para aparecer os itens importados}
end;

end.
